package com.lnsystem.service.impl;

import org.springframework.stereotype.Component;

import com.lnsystem.constants.LNSystemConstants;
import com.lnsystem.model.StockDailyData;
import com.lnsystem.service.CandleAnalyticsService;

@Component
public class CandleAnalyticsServiceImpl implements CandleAnalyticsService {
	
	@Override
	public boolean isDoji(StockDailyData dailyData) {
		return false;
	}
	
	@Override
	public boolean isLowerWickBigger(StockDailyData dailyData) {
		boolean result = false;
		
		if(dailyData!=null) {
			result =  getLowerWick(dailyData)>getUpperWick(dailyData);
		}
		
		return result;
	}
	@Override
	public boolean isAHammer(StockDailyData dailyData) {
		boolean result = false;
		
		if(dailyData!=null) {
			result =  (getLowerWick(dailyData)>getUpperWick(dailyData)*2 
					//(getUpperWick(dailyData)/getLowerWick(dailyData)*100)>LNSystemConstants.HAMMER_LOWERWICK_PERCENTAGE
					&& getLowerWick(dailyData)>Math.abs(dailyData.getOpen()-dailyData.getClose())
					);
		}
		
		return result;
	}
	@Override
	public boolean hasLowerWick(StockDailyData dailyData) {
		boolean result = false;
		
		if(dailyData!=null) {
			result =  getLowerWick(dailyData)>0;
		}
		
		return result;
	}
	
	@Override
	public boolean hasUpperWick(StockDailyData dailyData) {
		boolean result = false;
		
		if(dailyData!=null) {
			result =  getLowerWick(dailyData)>0;
		}
		
		return result;
	}
	
	@Override
	public boolean isLongLeggedDoji(StockDailyData dailyData) {
		
		return false;
	}

	public double getUpperWick(StockDailyData dailyData) {
		double upperWick;
		if(dailyData.getPriceAction().equals("G") || dailyData.getPriceAction().equals("H")) { //positive close
			upperWick = dailyData.getHigh() - dailyData.getClose();
		} else {
			upperWick = dailyData.getHigh() - dailyData.getOpen();
		}
		
		return upperWick;
	}
	
	public double getLowerWick(StockDailyData dailyData) {
		double lowerWick;
		if(dailyData.getPriceAction().equals("G") || dailyData.getPriceAction().equals("H")) { //positive close
			lowerWick = dailyData.getOpen() - dailyData.getLow();
		} else {
			lowerWick = dailyData.getClose() - dailyData.getLow();
		}
		
		return lowerWick;
	}
}
